using System.ComponentModel.DataAnnotations;

namespace Matrix.Configuration.Options
{
    /// <summary>
    /// 数据库配置选项
    /// </summary>
    public class DatabaseOptions
    {
        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        [Required]
        public string ConnectionString { get; set; } = string.Empty;

        /// <summary>
        /// 最大连接数
        /// </summary>
        [Range(1, 1000, ErrorMessage = "MaxConnectionCount must be between 1 and 1000")]
        public int MaxConnectionCount { get; set; } = 100;

        /// <summary>
        /// 命令超时时间（秒）
        /// </summary>
        [Range(1, 300, ErrorMessage = "CommandTimeout must be between 1 and 300")]
        public int CommandTimeout { get; set; } = 30;

        /// <summary>
        /// 是否启用失败重试
        /// </summary>
        public bool EnableRetryOnFailure { get; set; } = true;

        /// <summary>
        /// 最大重试次数
        /// </summary>
        [Range(0, 10, ErrorMessage = "MaxRetryCount must be between 0 and 10")]
        public int MaxRetryCount { get; set; } = 3;

        /// <summary>
        /// 是否启用敏感数据日志
        /// </summary>
        public bool EnableSensitiveDataLogging { get; set; }

        /// <summary>
        /// 是否启用详细错误
        /// </summary>
        public bool EnableDetailedErrors { get; set; } = true;

        /// <summary>
        /// 验证配置
        /// </summary>
        public void Validate()
        {
            if (string.IsNullOrWhiteSpace(ConnectionString))
                throw new ArgumentException("ConnectionString is required");

            if (MaxConnectionCount <= 0)
                throw new ArgumentException("MaxConnectionCount must be greater than 0");

            if (CommandTimeout <= 0)
                throw new ArgumentException("CommandTimeout must be greater than 0");
        }
    }
}